package com.taobao.applog;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import com.taobao.applog.core.jvm.JvmManager;

public class Main {
	
	/**
	 * run a jar file
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		
		JvmManager jm = new JvmManager();
		File workDir = new File("/home/java/resources");
		String stdout = "/home/java/stdout";
		String stderr = "/home/java/stderr";
		String pidFile = "/home/java/pid";
		long tailLength = 10000;
		
		// monitor args
		Map<String, String> env = new HashMap<String, String>() {
			
			{
				this.put("local.monitored.dir", "/home/monitor/workspace");
				this.put("com.sun.management.jmxremote.port", "9999");
				this.put("com.sun.management.jmxremote.password.file",
				        "/usr/develope/jdk1.6.0_17/jconsole_pwd/jmxremote.password");
				this.put("com.sun.management.jmxremote.ssl", "false");
				
			}
		};
		
		List<String> vargs = new ArrayList<String>();
		File jvm = // use same jvm as parent
		new File(new File(System.getProperty("java.home"), "bin"), "java");
		
		vargs.add(jvm.toString());
		
		for (Entry<String, String> e : env.entrySet()) {
			vargs.add("-D" + e.getKey() + "=" + e.getValue());
		}
		
		vargs.add("-jar");
		
		vargs.add("/home/java/resources/simple-0.0.1-SNAPSHOT.jar");
		
		vargs.add("Sniffer");
		
		jm.launchJvm(jm.constructJVM(vargs, stdout, stderr, workDir, env, pidFile, tailLength));
		
	}
	
}
